#include "Game.h"
#include "Camara.h"

#include <iostream>

using namespace std;


Camara::Camara(void):x(0.f),y(0.f)
	{
		locked = true;
		centrado = false;
	}

void Camara::update( int playerX, int playerY, int anchoMapa, int altoMapa)
	{
		if (locked){
			x = playerX + g->getAnchoPantalla()/2;
			y = playerY + g->getAltoPantalla()/2;

			if ( x > 0)
				x = 0;
			else if (x - g->getAnchoPantalla() < -anchoMapa && anchoMapa > g->getAnchoPantalla())
				x = -anchoMapa + g->getAnchoPantalla();

			if ( y > 0)
				y = 0;
			else if (y - g->getAltoPantalla() < - altoMapa && altoMapa > g->getAltoPantalla())
				y = -altoMapa + g->getAltoPantalla();
		}
		
	}
void Camara::translate(){
		glTranslatef(x,y,0.f);

	}
void Camara::unTranslate(){
		glTranslatef(-x,-y,0.f);
}
Camara::~Camara(void)
	{
	}

void Camara::setX( float x )
	{
		this->x = x /*+ g->getAnchoPantalla()/2*/;
	}

void Camara::setY( float y )
	{
		this->y = y /*+ g->getAltoPantalla()/2*/;
	}

void Camara::unlock()
	{
		locked = false;
	}
void Camara::lock(){
		centrado = false;
		locked = true;
	}